<?php include template('header');include template('top');?>
<div id="uc">
<?php include template('uc/left');?>
<div id="uc_main">
	<div class="uc_tab">
	<ul>
		<?php if($_GET['f'] == 'web'):?>
		<li><?php if(!$action): ?><span class="on"><a href="<?=url('home.php?f=web')?>">我的网址</a></span><?php else:?><a href="<?=url('home.php?f=web')?>">我的网址</a><?php endif;?></li>
		<li style="display:none;"><?php if($action == 'all'): ?><span class="on"><a href="<?=url('home.php?f=web&a=all')?>">所有网址</a></span><?php else:?><a href="<?=url('home.php?f=web&a=all')?>">所有网址</a><?php endif;?></li>
		<li><?php if($action == 'add'): ?><span class="on">添加网址</span><?php else:?><a href="<?=url('home.php?f=web&a=add')?>">添加网址</a><?php endif;?></li>
		<li><?php if($action == 'edit'): ?><span class="on">编辑网址</span><?php endif;?></li>
		<?php endif;?>
		<?php if($_GET['f'] == 'article'):?>
		<li><?php if(!$action): ?><span class="on"><a href="<?=url('home.php?f=article')?>">我的文章</a></span><?php else:?><a href="<?=url('home.php?f=article')?>">我的文章</a><?php endif;?></li>
		<li><?php if($action == 'all'): ?><span class="on"><a href="<?=url('article.php')?>" target="_blank">所有文章</a></span><?php else:?><a href="<?=url('article.php')?>">所有文章</a><?php endif;?></li>
		<li><?php if($action == 'add'): ?><span class="on">添加文章</span><?php else:?><a href="<?=url('home.php?f=article&a=add')?>">添加文章</a><?php endif;?></li>
		<li><?php if($action == 'edit'): ?><span class="on">编辑文章</span><?php endif;?></li>
		<?php endif;?>
		<?php if(!$_GET['f']):?>
		<li><font class="uc_w">{$_G['username']},欢迎您!</font> <font class="uc_t">上次登录时间:{echo gdate('Y/m/d H:i:s',$_G['users']['lastlogin'])}</font>   {if !$_G['users']['status']}您的账号还没激活,<b onclick="activeemail('{url user.php?f=ajax_active_mail}')";>点此激活账号</b>{/if}</li>
		<?php endif;?>
	</ul>
	</div>
	<div id="uc_contain">
	<?php if(!$_GET['f']):?>
		<dl class="statdl">
		<dd>收信箱:<?php echo intval($stat['msg']);?>(<?php echo intval($stat['msg']);?>条新信息),<a href="<?php echo url("home.php?f=msg&a=outbox");?>" target="_blank">发信箱</a><a href="<?php echo url("home.php?f=msg&a=add");?>" target="_blank">写信</a></dd>
		<dd>积分数:<?php echo intval($stat['point1']);?>, <?php if($stat['points_order']):?><?php echo $stat['points_order'];?>个订单未付款(<a href="home.php?f=point" target="_blank">查看/去支付</a>), <?php endif;?><a href="<?php echo url("home.php?f=point&a=recharge");?>" target="_blank">购买积分</a></dd>
		</dl>
	<?php endif;?>
<?php if($_GET['f'] == 'web'):?>
	<?php if(!$action || $action=='all' ): ?>
		<table class="uc_table" >
				<tr>
				<th><?php echo $lang['name'];?></th><th><?php echo $lang['description'];?></th><th><?php echo $lang['category'];?></th><th style="width:100px;"><?php echo $lang['time'];?></th><th style="width:50px;"><?php echo $lang['view'];?></th><th style="width:50px;"><?php echo $lang['comment'];?></th><th style="width:50px;"><?php echo $lang['collection'];?></th>
				<th style="width:170px;"><?php echo $lang['operation'];?></th>
				</tr>
				<?php foreach($links as $link) :?>
				<tr id="lk<?php echo $link['lid'];?>">
				<td><a href="<?php echo $link['url'];?>" target="_blank"><?php echo $link['title'];?></a></td>
				<td><?php echo $link['summary'];?></td>
				<td><a href="<?php echo url('home.php?f=web&a='.$action.'&id='.$link['cid'])?>"><?php echo $link['catename']?></a></td>
				<td><?php echo gdate('Y年m月d日',$link['dateline']); ?></td>
				<td><?php echo $link['views'];?></td>
				<td><?php echo $link['comments'];?></td>
				<td><?php echo $link['collection'];?></td>
				<td><a href="<?php echo $link['url'];?>" target="_blank">[<?php echo $lang['view'];?>]</a><?php if($link['rssurl']):?><a href="<?php echo url('home.php?f=myread&a=add&lid='.$link['lid']);?>" target="_blank">[<?php echo $lang['read'];?>]</a><?php endif;?><a href="<?php echo url('home.php?f=web&a=edit&id='.$link['lid']);?>">[<?php echo $lang['edit'];?>]</a><a href="<?php echo url('home.php?f=web&a=del&id='.$link['lid']);?>"  onclick="return deletelink(this.href,'lk<?php echo $link['lid'];?>');"  target="_blank">[<?php echo $lang['delete'];?>]</a></td>
				</tr>
				<?php endforeach;?>
				
		</table>		
		<?=$pager?>
		<script type="text/javascript">
	
				function deletelink(u,id){
					if(confirm('<?php echo $lang["confirm_delete"];?>')){
						$.getJSON(u+'&inajax=1&tm='+Math.random(),'',function(data){
							if(data.status==true){
								$('#'+id).hide();
							}else{
								alert(data.msg);
							}
							});
					}
					return false;
					
				}
			</script>
	<?php elseif ($action=='edit' || $action=='add'):?>
		<form name="save" method="post" action="<?=url('home.php?f=web&a=save')?>" onsubmit="return save_link()">
		<input type="hidden" name="savetype" value="<?=$action?>" />
		<input type="hidden" name="id" value="<?=$result['lid']?>" />
		<table width="100%" cellspacing="0" class="sub">
			<tr>
				<td colspan="2"><div id="tip"></div></td>
			</tr>
			<tr>
				<td width="80" align="right">网站名称：</td>
				<td><input type="text" name="title" class="input" size="20" value="<?=$result['title']?>" /> 
				<select name="cid"><?=get_category_options($result['cid'],1)?></select>
				</td>
			</tr>
			<tr>
				<td align="right">URL：</td>
				<td><input type="text" name="url" class="input" size="50" value="<?=$result['url']?>" /> <span>别忘了加上http://</span></td>
			</tr>
			<tr>
				<td align="right">RSS地址：</td>
				<td><input type="text" name="rssurl" class="input" size="50" value="<?=$result['rssurl']?>" /> <span>别忘了加上http://</span></td>
			</tr>
			<tr>
				<td align="right">描述：</td>
				<td><textarea name="summary" rows="5" cols="50"><?=$result['summary']?></textarea>
				</td>
			</tr>
			<tr>
				<td align="right">访问权限：</td>
				<td><input type="radio" name="visible" id="visible" value="1" class="checkbox" <?php if($result['visible'] == 1):?>checked="checked"<?php endif;?> /><label for="visible1">公开</label> <input type="radio" name="visible" value="2" class="checkbox" <?php if($result['visible'] == 2):?>checked="checked"<?php endif;?>/><label for="visible0">自己可见</label> <input type="radio" name="visible" value="3" class="checkbox" <?php if($result['visible'] == 3):?>checked="checked"<?php endif;?>/><label for="visible0">好友可见</label>
				</td>
			</tr>
			<tr class="bg2"><td></td><td><input type="submit" class="button" value="保存链接" /> <input type="button" class="button" onclick="history.back();" value="取消返回" /></td></tr>
		</table>
		</form>
	<?php endif;?>
	
<?php endif;?>


<?php if($_GET['f'] == 'article'):?>
	<?php if($action == 'add' || $action == 'edit' ):?>
			
			
	<form name="save" method="post" action="<?php echo url('home.php?f=article&a=save');?>" onsubmit="return check_write()">
	<input type="hidden" name="todraft" id="todraft" value="0" />
	<input type="hidden" name="aid" value="<?=$article['aid']?>" />
		<table class="sub">
			<tr>
				<td width="40">标题：</td>
				<td><input type="text" name="title" class="input" size="54" value="<?=$article['title']?>" onfocus="if(this.value=='未命名文章')this.value=''" /></td>
			</tr>
			<tr>
				<td>分类：</td>
				<td>
				<select name="cid" id="cid">
					<option value="0">请选择类别</option>
					<?php  foreach($categorys as $cate):?>
					<option value="<?php echo $cate['cid'];?>" <?php if($cate['cid'] == $article['cid']):?>selected="selected"<?php endif;?>><?php echo $cate['catename']?></option>
					<?php endforeach;?>
				</select>
					<span><a href="javascript:;" onclick="$('#createcadiv').toggle();">添加类别</a></span>
					<div id="createcadiv">
					<h3><a href="javascript:;" onclick="$('#createcadiv').toggle();" title="<?php echo $lang['close'];?>" style="float:right;">×</a>添加类别</h3>
						<p>分类名称：<input type="text" name="ucatename" id="ucatename" class="input"/></p>
						
						<p>浏览权限：<input type="radio" checked="checked" value="0" name="cstatus">完全开放
						<input type="radio" value="1" name="cstatus">
						仅好友可见
						<input type="radio" value="2" name="cstatus">
						仅自己可见
						</p><p>
						<input type="button" class="button" onclick="useraddcates();" value="保存类别"/></p>
					</div>
				阅读权限：
				<select name="status">
					<option value="0" <?=$article['status'] == 1 ? 'selected="selected"':''?>>继承类别权限</option>
					<option value="1" <?=$article['status'] == 1 ? 'selected="selected"':''?>>完全开放</option>
					<option value="5" <?=$article['status'] == 5 ? 'selected="selected"':''?>>仅好友可见</option>
					<option value="3" <?=$article['status'] == 3 ? 'selected="selected"':''?>>仅自己可见 </option>
				</select>
				
				
				</td>
			</tr>
			<tr>
				<td>摘要：</td><td>
					<textarea rows="" cols="53" name="summary" id="summary"><?php echo $article['summary'];?></textarea>
					</td>
			</tr>

			</tbody>
			<?php if ( isset($attachments) && count($attachments) ) : ?>
			<tr>
				<td>附件：</td>
				<td><input type="checkbox" name="show_attachments" value="1" onclick="$('#attachments').toggle()" id="show_attachments" class="checkbox" checked="checked" /><label for="show_attachments">显示该文章下的附件</label></td>
			</tr>
			<tbody id="attachments">
			<tr>
				<td></td>
				<td>
				<table width="98%" cellspacing="1">
					<tr>
						<th width="50">ID</th>
						<th>文件名</th>
						<th width="80">文件大小</th>
						<th width="120">上传时间</th>
						<th width="50">操作</th>
					</tr>
					<?php
					foreach ( $attachments as $attach ) : 
					?>
					<tr id="tr_<?=$attach['fid']?>" onmouseover="this.className='bg2'" onmouseout="this.className=''">
						<td width="50"><?=$attach['fid']?></td>
						<td>
						<?php
						if ( stristr($attach['filetype'], 'image') ) {
							$src = empty($attach['thumb']) ? $attach['filepath'] : $attach['thumb'];
							$preview ='<div class="preview" id="attach_'.$attach['fid'].'"><img src="'.$src.'" class="thumb" /></div>';
							$insert = '<img src=\'+\''.$attach['filepath'].'\'+\'></img>';
						} else {
							$preview = '';
							$insert = '[file]'.$src.'[/file]';
						}
						echo '[<a href="javascript:;" onclick="insert_attach(\'content\', \''.$insert.'\')">插入</a>] <a href="'.$insert.'" target="_blank" class="attach">'.$attach['originalname'].$preview.'</a>';
						?>
						</td>
						<td width="80"><?=sizecount($attach['filesize'])?></td>
						<td width="120"><?=gdate('Y-m-d H:i',$attach['dateline'])?></td>
						<td width="50"><a href="javascript:;" onclick="del_attach(<?=$attach['fid']?>)">删除</a></td>
					</tr>
					<?php endforeach;?>
				</table>
				</td>
			</tr>
			</tbody>
			<?php endif; ?>
			<tr>
				<td valign="top">内容：</td><td><?=editor('content','content',$article['content'].'','default','100%','250px',true)?></td>
			</tr>
			<tr>
			<td></td><td>
				<input type="submit" class="button" value="保存文章" />
				<input type="button" class="button" value="另存为草稿" onclick="save_to_draft()" />
				<input type="button" class="button" value="返回上一页" onclick="history.back()" />
			</td>
			</tr>
		</table>
	</form>
	<script type="text/javascript">
	function useraddcates(){
		var name=$('#ucatename').val();
		var cstatus= $("input[name='cstatus']:checked").val();
		if(name.length<2){alert('分类名称不能少于两个字符');return false;}
		var u= "home.php?f=article&a=addcates";
		$.getJSON("home.php?f=category&a=save"+"&name="+name+"&cstatus="+cstatus+'&tm='+Math.random(),'',function(data){
			if(data.mstatus==true){
				var obj = document.getElementById("cid");
					obj.options.add(new Option(data.catename, data.cid));
					obj.options[obj.options.length-1].selected=true;
				$('#createcadiv').hide();
			}else{
				alert(data.msg);
				$('#ucatename').focus();
			}
			});

	}
				</script>
			
			
	<?php endif;?>
<?php endif;?>
</div>
</div>
</div>
<?php include template('footer')?>